<template>
  <vxe-modal
    title="办理任务"
    v-model="dialogVisible"
    v-if="dialogVisible"
    width="70%" height="87vh" showFooter esc-closable show-zoom resize>

    <div style="height: 52vh; overflow-y: auto;">
      <el-tabs type="border-card">
        <el-tab-pane label="基本资料">
          <span slot="label"><svg-icon icon-class="jbzl"/> 基本资料</span>

          <el-descriptions class="margin-top" :column="2" size="medium" border
                           :contentStyle="content_style" :labelStyle="label_style">
            <el-descriptions-item>
              <template slot="label">
                <div class="right-align-label">
                  <i class="el-icon-user"></i>
                  姓名：
                </div>
              </template>
              {{ rowDatas.name }}
            </el-descriptions-item>
            <el-descriptions-item>
              <template slot="label">
                <div class="right-align-label">
                  <i class="el-icon-office-building"></i>
                  性别：
                </div>
              </template>
              <dict-tag :options="dict.type.sys_user_sex" :value="rowDatas.sex"/>
            </el-descriptions-item>
            <el-descriptions-item>
              <template slot="label">
                <div class="right-align-label">
                  <i class="el-icon-user"></i>
                  身份证号：
                </div>
              </template>
              {{ rowDatas.sfzh }}
            </el-descriptions-item>
            <el-descriptions-item>
              <template slot="label">
                <div class="right-align-label">
                  <i class="el-icon-user"></i>
                  出生日期：
                </div>
              </template>
              {{ rowDatas.csrq }}
            </el-descriptions-item>
            <el-descriptions-item>
              <template slot="label">
                <div class="right-align-label">
                  <i class="el-icon-office-building"></i>
                  职称：
                </div>
              </template>
              <dict-tag :options="dict.type.rcpt_zc" :value="rowDatas.zc"/>
            </el-descriptions-item>
            <el-descriptions-item>
              <template slot="label">
                <div class="right-align-label">
                  <i class="el-icon-user"></i>
                  职务：
                </div>
              </template>
              {{ rowDatas.zw }}
            </el-descriptions-item>
            <el-descriptions-item>
              <template slot="label">
                <div class="right-align-label">
                  <i class="el-icon-user"></i>
                  学历：
                </div>
              </template>
              {{ rowDatas.xl }}
            </el-descriptions-item>
            <el-descriptions-item>
              <template slot="label">
                <div class="right-align-label">
                  <i class="el-icon-user"></i>
                  毕业院校：
                </div>
              </template>
              {{ rowDatas.byYx }}
            </el-descriptions-item>
            <el-descriptions-item>
              <template slot="label">
                <div class="right-align-label">
                  <i class="el-icon-user"></i>
                  所学专业：
                </div>
              </template>
              {{ rowDatas.sxZy }}
            </el-descriptions-item>
            <el-descriptions-item>
              <template slot="label">
                <div class="right-align-label">
                  <i class="el-icon-office-building"></i>
                  熟悉领域：
                </div>
              </template>
              <dict-tag :options="dict.type.rcpt_sxly" :value="rowDatas.sxLy"/>
            </el-descriptions-item>
            <el-descriptions-item>
              <template slot="label">
                <div class="right-align-label">
                  <i class="el-icon-office-building"></i>
                  人员分类：
                </div>
              </template>
              <dict-tag :options="dict.type.rcpt_ryfl" :value="rowDatas.ryFl"/>
            </el-descriptions-item>
            <el-descriptions-item>
              <template slot="label">
                <div class="right-align-label">
                  <i class="el-icon-office-building"></i>
                  是否专家：
                </div>
              </template>
              <dict-tag :options="dict.type.rcpt_sf" :value="rowDatas.sfZj"/>
            </el-descriptions-item>
            <el-descriptions-item>
              <template slot="label">
                <div class="right-align-label">
                  <i class="el-icon-office-building"></i>
                  电话 ：
                </div>
              </template>
              {{ rowDatas.phone }}
            </el-descriptions-item>
            <el-descriptions-item>
              <template slot="label">
                <div class="right-align-label">
                  <i class="el-icon-office-building"></i>
                  QQ ：
                </div>
              </template>
              {{ rowDatas.qq }}
            </el-descriptions-item>
            <el-descriptions-item>
              <template slot="label">
                <div class="right-align-label">
                  <i class="el-icon-office-building"></i>
                  是否在职：
                </div>
              </template>
              <dict-tag :options="dict.type.rcpt_sf" :value="rowDatas.sfZz"/>
            </el-descriptions-item>
            <el-descriptions-item>
              <template slot="label">
                <div class="right-align-label">
                  <i class="el-icon-office-building"></i>
                  所属单位 ：
                </div>
              </template>
              {{ rowDatas.ssDw }}
            </el-descriptions-item>
            <el-descriptions-item>
              <template slot="label">
                <div class="right-align-label">
                  <i class="el-icon-office-building"></i>
                  专业特长 ：
                </div>
              </template>
              {{ rowDatas.zyTc }}
            </el-descriptions-item>
          </el-descriptions>

          <el-descriptions class="margin-top" :column="1" size="medium" border direction="vertical">
            <el-descriptions-item>
              <template slot="label">
                <div>
                  <i class="el-icon-office-building"></i>
                  个人简介 ：
                </div>
              </template>
              {{ rowDatas.grJj }}
            </el-descriptions-item>
            <el-descriptions-item>
              <template slot="label">
                <div>
                  <i class="el-icon-office-building"></i>
                  证件照 ：
                </div>
              </template>
              <image-preview :src="rowDatas.zjZ" :width="100" :height="100" show-overflow-tooltip/>
            </el-descriptions-item>
          </el-descriptions>


        </el-tab-pane>
        <el-tab-pane label="工作履历">
          <span slot="label"><i class="el-icon-date"></i> 工作履历</span>

          <el-table :header-cell-style="{background:'#d0cece',color:'#000000',fontWeight:'bold'}"
                    :data="kjRyGzlvData">
            <el-table-column label="序号" align="center" type="index" width="50"/>
            <el-table-column label="开始时间" align="center" prop="ksTime" width="110"/>
            <el-table-column label="截止时间" align="center" prop="jzTime" width="110"/>
            <el-table-column label="单位/部门" align="center" prop="dwBm"/>
            <el-table-column label="职务" align="center" prop="zw"/>
            <el-table-column label="负责内容" align="center" prop="fzNr"/>
          </el-table>

        </el-tab-pane>
        <el-tab-pane label="附件资料">
          <span slot="label"><i class="el-icon-date"></i> 附件资料</span>

          <el-table :header-cell-style="{background:'#d0cece',color:'#000000',fontWeight:'bold'}"
                    :data="kjRyFjData">
            <!--            <el-table-column label="序号" align="center" type="index" width="50"/>-->
            <el-table-column label="文件名称" align="center" prop="fileName" show-overflow-tooltip
                             :formatter="getFileNames"/>
            <el-table-column label="文件大小" align="center" prop="fileSize" width="120"/>
            <el-table-column label="上传时间" align="center" prop="scTime" width="120"/>
            <el-table-column label="上传人" align="center" prop="scUser" width="120"/>
            <el-table-column label="操作" width="120" align="center" class-name="small-padding fixed-width">
              <template slot-scope="scope">
                <el-button
                  size="mini"
                  type="text"
                  icon="el-icon-edit"
                  @click="handleDownload(scope.row)"
                >下载
                </el-button>
              </template>
            </el-table-column>
            <!-- 其他列配置 -->
          </el-table>

        </el-tab-pane>
      </el-tabs>
    </div>
    <el-divider></el-divider>

    <el-card shadow="never">
    <el-form label-width="100px">
      <el-form-item label="审核状态：">
        <el-radio label="1" v-model="submitType">同意</el-radio>
        <el-radio label="2" v-model="submitType">驳回</el-radio>
        <el-select remote v-if="submitType==='2'" v-model="denyTo" placeholder="驳回到：" @visible-change="selectBefore">
          <el-option
            v-for="item in beforeData"
            :key="item.dkey"
            :label="item.taskName"
            :value="item.dkey">
          </el-option>
        </el-select>
      </el-form-item>

      <el-form-item label="审核意见：">
        <el-input type="textarea" v-model="comment"></el-input>
      </el-form-item>
    </el-form>
    </el-card>

    <div slot="footer" class="dialog-footer dialog-footer-center">
      <el-button type="primary" @click="onSubmit()">提交</el-button>
      <el-button @click="dialogVisible=false">关闭</el-button>
    </div>
  </vxe-modal>
</template>
<script>

import {fallBackTask, fallBackTaskByTaskDefinitionKey, passTask, selectBefore, selectHistory} from "@/api/activiti/task"
import {getKjry, selectKjryGzlvByKjryId} from "@/api/kjry/kjry";

export default {
  name: "kjrySq",
  dicts: ['sys_user_sex', 'rcpt_zc', 'rcpt_sxly', 'rcpt_ryfl', 'rcpt_sf'],
  data() {
    return {
      beforeData: [],
      beforeDataLoading: false,
      denyTo: null,
      rowDatas: null,
      dialogVisible: false,
      rowData: null,
      submitType: "1",//默认同意
      comment: null,//审批意见
      businessData: null,//业务数据
      historyList: [],//历史信息
      content_style: {
        // 解决不对齐的问题
        'width': "400px",
        // 排列第二行
        'word-break': 'break-all',
        // 'background-color': '#f3f7ff'
      },
      label_style: {
        // 解决不对齐的问题
        'width': "250px",
        // 排列第二行
        'word-break': 'break-all',
      },
      kjRyFjData: [], //附件资料列表
      kjRyGzlvData: [], //科技人员工作履历列表
    };
  },
  created() {
  },
  methods: {
    // 文件下载处理
    handleDownload(row) {
      const resource = row.fileName;
      // 默认方法
      this.$download.resource(resource);
    },
    getFileNames(row) {
      // 从路径中提取文件名
      return row.fileName.split('/').pop(); // 返回文件名部分
    },
    handleOpen(row) {
      this.rowData = row
      this.rowDatas = row
      this.dialogVisible = true
      this.getInfoQingJiaData()
    },
    //获取之前的节点信息
    selectBefore(visible){
      //console.log(this.rowData.taskId, "======selectBefore")
      if (visible) {
        this.beforeDataLoading = true;
        this.denyTo = null;
        this.beforeData = [];
        selectBefore({taskId: this.rowData.taskId,
          comment: this.comment,
          businessKey: this.rowData.businessKey,
          businessType: this.rowData.businessType,
          processInstanceId: this.rowData.processInstanceId}).then(res => {
          console.table(res);
          setTimeout(() => {
            this.beforeData = res.data;
            this.beforeDataLoading = false;
          }, 100); // 模拟异步加载数据
          //this.$options = res.data
        })
      }
    },
    //获取详情数据
    getInfoQingJiaData() {
      getKjry(this.rowDatas.businessKey).then(res => {
        this.rowDatas = res.data
        this.kjRyFjData = res.data.kjryFjList //将科技人员附件赋值到kjRyFjData
      })
      //根据科研人员ID查询工作履历列表
      selectKjryGzlvByKjryId(row.kjryId).then(res => {
        this.kjRyGzlvData = res.data.kjryGzlvList
      })

    },
    clickTab(tab, event) {
      if (tab.name === 'history') {
        this.getSelectHistory()
      }
    },
    //获取历史记录
    getSelectHistory() {
      selectHistory({processInstanceId: this.rowData.processInstanceId}).then(res => {
        this.historyList = res.data
      })
    },
    //提交
    onSubmit() {
      if (!this.submitType) {
        this.$message.warning("请选择提交类型")
        return
      }
      if (!this.comment) {
        this.$message.warning("请输入审批意见")
        return
      }
      if (this.submitType == 1) {
        console.log(this.rowData, '1111111111111111111111111111111')
        //审核通过
        passTask({
          taskId: this.rowData.taskId,
          comment: this.comment,
          params: {
            // day: this.businessData.qingJiaDay
          },
          businessKey: this.rowData.businessKey,
          businessType: this.rowData.businessType,
          processInstanceId: this.rowData.processInstanceId
        }).then(res => {
          this.dialogVisible = false
          this.$emit('ok')
        })
      }
      //任务驳回
      if (this.submitType == 2) {
        console.log("nnnnnnnnn"+this.denyTo);
        //审核不通过
        fallBackTaskByTaskDefinitionKey({
          comment: this.comment,
          businessKey: this.rowData.businessKey,
          businessType: this.rowData.businessType,
          processInstanceId: this.rowData.processInstanceId,
          taskId: this.rowData.taskId,
          taskDefinitionKey:this.denyTo
        }).then(res => {
          console.log(res, "[[[[")
          this.dialogVisible = false
          this.denyTo = null;
          this.beforeData =[];
          this.$emit('ok')
        })
      }
    },

  }
};
</script>

